#ifndef  _HARDWARE_TOUCH_H
#define  _HARDWARE_TOUCH_H

#include "system_ch32v30x.h"

#define TOUCH_LCD_WIDTH  240
#define TOUCH_LCD_HEIGHT 320
#define TOUCH_READ_X_POINT 0xD0
#define TOUCH_READ_Y_POINT 0x90

#define TOUCH_CALIBRATE_POINT_COLOR 0xF800
#define TOUCH_CALIBRATE_POINT_CLEAR 0xFFFF

#define TOUCH_CALIBRATE_FIR_POINT_X (20)
#define TOUCH_CALIBRATE_FIR_POINT_Y (20)

#define TOUCH_CALIBRATE_SEC_POINT_X (TOUCH_LCD_WIDTH - 20)
#define TOUCH_CALIBRATE_SEC_POINT_Y (20)

#define  TOUCH_CALIBRATE_THI_POINT_X (20)
#define  TOUCH_CALIBRATE_THI_POINT_Y (TOUCH_LCD_HEIGHT - 20)

#define TOUCH_CALIBRATE_FOU_POINT_X (TOUCH_LCD_WIDTH  - 20)
#define TOUCH_CALIBRATE_FOU_POINT_Y (TOUCH_LCD_HEIGHT - 20)



#define TOUCH_DBG_FLAG          1

#if TOUCH_DBG_FLAG
#define TOUCH_DBG(fmt, arg...) printf( "touch: " fmt "\r\n" , ## arg)
#else
#define TOUCH_DBG(fmt, arg...)
#endif

#define XPT2046_CALIBRATE_GET_MAX_POINT 5

typedef struct {
    float x_factory;
    float y_factory;
    uint16_t px[XPT2046_CALIBRATE_GET_MAX_POINT];
    uint16_t py[XPT2046_CALIBRATE_GET_MAX_POINT];
    float b_x;
    float b_y;
}touch_config_struct;

void touch_hardware_init(void);
uint8_t touch_hardware_is_pressed(void);
uint8_t touch_hardware_calibrate(touch_config_struct* cfg);
void touch_hardware_set_read_config(touch_config_struct* cfg);
void touch_hardware_reab_point(uint16_t* x,uint16_t* y);


#endif
